import * as Sequelize from 'sequelize';
import { DataTypes, Model, Optional } from 'sequelize';

export interface newsAttributes {
  id: number;
  title: string;
  content?: string;
  from?: number;
  to: number;
  type: number;
  read: number;
  commentId?: number;
  replyId?: number;
  noteId?: number;
  createdAt: Date;
  updatedAt: Date;
}

export type newsPk = "id";
export type newsId = news[newsPk];
export type newsOptionalAttributes = "id" | "content" | "from" | "read" | "commentId" | "replyId" | "noteId" | "createdAt" | "updatedAt";
export type newsCreationAttributes = Optional<newsAttributes, newsOptionalAttributes>;

export class news extends Model<newsAttributes, newsCreationAttributes> implements newsAttributes {
  id!: number;
  title!: string;
  content?: string;
  from?: number;
  to!: number;
  type!: number;
  read!: number;
  commentId?: number;
  replyId?: number;
  noteId?: number;
  createdAt!: Date;
  updatedAt!: Date;


  static initModel(sequelize: Sequelize.Sequelize): typeof news {
    return news.init({
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER.UNSIGNED,
      allowNull: false,
      primaryKey: true,
      comment: "主键ID"
    },
    title: {
      type: DataTypes.STRING(50),
      allowNull: false
    },
    content: {
      type: DataTypes.STRING(255),
      allowNull: true
    },
    from: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    to: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    type: {
      type: DataTypes.TINYINT,
      allowNull: false,
      comment: "1 评论 2 回复 3 审核消息"
    },
    read: {
      type: DataTypes.TINYINT,
      allowNull: false,
      defaultValue: 0,
      comment: "0 未读 1 已读 默认 0"
    },
    commentId: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    replyId: {
      type: DataTypes.INTEGER,
      allowNull: true
    },
    noteId: {
      type: DataTypes.INTEGER,
      allowNull: true
    }
  }, {
    sequelize,
    tableName: 'news',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
    ]
  });
  }
}
